﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kristall.Screens;
using System.Windows.Forms;
using System.Xml.Serialization;
using System.IO;
using System.Reflection;
using Kristall.Engine;

namespace Kristall.Editor.Commands
{
    public class CopyCommand : ICommand
    {
        AABB _toCopy;

        public CopyCommand(AABB toCopy)
        {
            _toCopy = toCopy;
            copy();
        }

        void copy()
        {
            try
            {
              XmlSerializer serializer = new XmlSerializer(typeof(AABB), Kristall.GetExtraTypes()); //new[] { typeof(Light) });
              MemoryStream ms = new MemoryStream();
              serializer.Serialize(ms, _toCopy);

              DataObject dataObject = new DataObject(ToolPalette.AnimatableDataFormat.Name, ms.ToArray());
              Clipboard.SetDataObject(dataObject);
            }
            catch (Exception e)
            {
                Kristall.Console.Echo(e.Message);
                string msg = e.Message;
                if (e.InnerException != null)
                    msg += " Inner: " + e.InnerException.Message;
                MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        public bool Execute()
        {
            copy();
            return true;
        }

        public bool Undo()
        {
            Clipboard.Clear();
            return true;
        }

        public string Name
        {
            get { return "Copy"; }
        }
    }
}
